/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import database_beans.Predmet;
import database_beans.Raspored;
import database_beans.Student;
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import org.hibernate.Hibernate;
import server.Log;

/**
 *
 * @author stefan
 */
@ManagedBean
@RequestScoped
public class StudentBean implements Serializable{
    
    @ManagedProperty("#{userBean}")
    private UserBean user;

    private Predmet selectedPredmet;

    private ArrayList<Predmet> predmetList;

    /**
     * Creates a new instance of StudentBean
     */
    public StudentBean() {
    }
    
    @PostConstruct
    public void init(){
        predmetList = getPredmetList(user.getStudent());
        selectedPredmet = new Predmet();
        Log.i("Konstruktor student beana");
    }
    
    public ArrayList<Predmet> getPredmetList(Student s) {
        if (s == null) {
            return null;
        }
        ArrayList<Predmet> list = new ArrayList<Predmet>();
        for (Raspored r : new ArrayList<Raspored>(s.getRasporeds())) {
            list.add(r.getPredmet());
        }
        for (Predmet p : list) {
            Hibernate.initialize(p.getLabVezbes());
            Hibernate.initialize(p.getDomacis());
            Hibernate.initialize(p.getMaterijalis());
            Hibernate.initialize(p.getObavestenjas());
        }
        return list;
    }

    public UserBean getUser() {
        return user;
    }

    public void setUser(UserBean user) {
        this.user = user;
    }

    public Predmet getSelectedPredmet() {
        return selectedPredmet;
    }

    public void setSelectedPredmet(Predmet selectedPredmet) {
        this.selectedPredmet = selectedPredmet;
    }

    public ArrayList<Predmet> getPredmetList() {
        return predmetList;
    }

    public void setPredmetList(ArrayList<Predmet> predmetList) {
        this.predmetList = predmetList;
    }
    
 
}
